package com.friendar.webapp;

import java.sql.Date;

public class FriendInfoDTO {
	
	public int friendID;
	public String friendName= null;
	public String friendPhone = null;
	public String friendEmail = null;
	public int userID;
	public long distance;
	public String lat;
	public String longi;
	public Date dtLoc;
	public boolean f1;
	
	/**
	 * Creates a string representation of this object for logging and other purposes
	 */
	public String toString() {
		StringBuffer buf = new StringBuffer();
		buf.append("User: " + userID);
		buf.append(" Friend: " + friendName + "(" + friendID + ")");

		buf.append("\nDistance: " + distance);
		buf.append("\nOther friend info: " + friendPhone + ", " + friendEmail);
		return buf.toString();
	}
	
	/**
	 * Creates a XML representation of this object for data transfer
	 * @return XML representation
	 */
	public String toXML() {
		StringBuffer buf = new StringBuffer();
		// constants needed to construct the xml
		// can be potentially moved to some constants file or something
		String start = "<friend_location>";
		String end = "</friend_location>";
		String name = "<name>XX</name>";
		String phone = "<phone>XX</phone>";
		String dist =  "<distance>XX</distance>";
		String dt = "<date_time>XX</date_time>";
		String email = "<email>XX</email>";
		
		// start constructing the XML by appending strings
		buf.append(start);
		buf.append(name.replaceAll("XX", friendName));
		buf.append(email.replaceAll("XX", friendEmail));
		buf.append(phone.replaceAll("XX", friendPhone));
		buf.append(dist.replaceAll("XX", Long.toString(distance)));
		buf.append(dt.replaceAll("XX", dtLoc.toString()));
		buf.append(end);
		
		return buf.toString();
		
	}
}
